// pages/user/my-votes/my-votes.js
const voteApi = require('../../../api/vote.js')
const util = require('../../../utils/util.js')

Page({
  data: {
    votes: [],
    loading: false
  },

  onLoad() {
    this.loadMyVotes()
  },

  async loadMyVotes() {
    this.setData({ loading: true })
    
    try {
      const res = await voteApi.getMyVotes()
      
      if (res.code === 200) {
        this.setData({
          votes: res.data.items
        })
      }
    } catch (error) {
      console.error('加载加油记录失败:', error)
      util.showError('加载失败')
    } finally {
      this.setData({ loading: false })
    }
  },

  onPullDownRefresh() {
    this.loadMyVotes()
    wx.stopPullDownRefresh()
  }
})

